<html>
<head><meta charset="utf-8"><title>Check if local is alive · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html">Check if local is alive</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232290066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290066">(Mar 29 2021 at 15:48)</a>:</h4>
<p>Hi, is there a way to know if a local is alive in a particular MIR location?</p>



<a name="232290291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290291">(Mar 29 2021 at 15:50)</a>:</h4>
<p>yes <span aria-label="stuck out tongue wink" class="emoji emoji-1f61c" role="img" title="stuck out tongue wink">:stuck_out_tongue_wink:</span></p>



<a name="232290314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290314">(Mar 29 2021 at 15:50)</a>:</h4>
<p>how?</p>



<a name="232290321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290321">(Mar 29 2021 at 15:50)</a>:</h4>
<p>:O</p>



<a name="232290333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290333">(Mar 29 2021 at 15:50)</a>:</h4>
<p>You will need a dataflow analysis for that: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/index.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/index.html</a></p>
<p>I think <code>MaybeRequiresStorage</code> is the most suitable.</p>



<a name="232290340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290340">(Mar 29 2021 at 15:50)</a>:</h4>
<p>there is a MIR dataflow visitor for just this</p>



<a name="232290460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290460">(Mar 29 2021 at 15:51)</a>:</h4>
<p>if by "alive" you mean an actual liveness analysis, we have that too</p>



<a name="232290675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290675">(Mar 29 2021 at 15:52)</a>:</h4>
<p>I think that I actually care about each local being initialized so I suppose this one should be adequate: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/struct.MaybeInitializedLocals.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/struct.MaybeInitializedLocals.html</a></p>



<a name="232290681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232290681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232290681">(Mar 29 2021 at 15:52)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/struct.MaybeLiveLocals.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/dataflow/impls/struct.MaybeLiveLocals.html</a></p>



<a name="232291199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232291199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232291199">(Mar 29 2021 at 15:56)</a>:</h4>
<p>and is the output of those analysis cached?</p>



<a name="232291736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232291736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232291736">(Mar 29 2021 at 15:59)</a>:</h4>
<p>not globally. But while running the analysis it is very cheap to move the cursor in one direction</p>



<a name="232291941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232291941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232291941">(Mar 29 2021 at 16:00)</a>:</h4>
<p>so if I use the visitor i can just request the result of the analysis on each location I need efficiently. i should RTFM right? <a href="https://rustc-dev-guide.rust-lang.org/mir/dataflow.html?highlight=dataflow#dataflow-analysis">https://rustc-dev-guide.rust-lang.org/mir/dataflow.html?highlight=dataflow#dataflow-analysis</a></p>



<a name="232292254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Check%20if%20local%20is%20alive/near/232292254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Check.20if.20local.20is.20alive.html#232292254">(Mar 29 2021 at 16:02)</a>:</h4>
<p>oh I just saw the dot graphs, this is awesome! thank you</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>